<?php
/**
 * Created by PhpStorm.
 * User: 海峡
 * Date: 2021/1/5
 * Time: 15:43
 */
/**
 *
 * @param array $data 结果集 (整个表的结果)
 * @param int $fid 父类ID
 * @param array $result 结果数据
 * @param int $deep 分类级数
 * @return array
 */
function getTree($list, $pid = 0, &$result = array(), $deep = 0)
{
    $deep += 1;
    foreach ($list as $k=>$v){   //遍历之后，此处的$k是键(其实是数组的序列号)，$v是一条数据结果
        if($v->pid==$pid){
            $result[$k]['id'] = $v->id;
            $result[$k]['name'] = "|".str_repeat("-", $deep).$v->name;
            $result[$k]['url'] = $v->url;
            $result[$k]['pid'] = $v->pid;
            getTree($list, $v->id, $result, $deep);
        }else{
            continue;
        }
    }
    return $result;
}